import java.util.concurrent.FutureTask;

/**
 * @Auther: MFM
 * @Date: 2021/10/31 - 10 - 31 - 18:58
 * @version: 1.0
 */

public class Demo extends Thread {
    @Override
    public void run() {
        System.out.println("把多个任务拆解成小任务");

        callTask callable1 = new callTask<>(1, 3000);
        FutureTask<Integer> task1 = new FutureTask<Integer>(callable1);
        Thread th1 = new Thread(task1);

        callTask callable2 = new callTask<>(2, 2000);
        FutureTask<Integer> task2 = new FutureTask<Integer>(callable2);
        Thread th2 = new Thread(task2);

        callTask callable3 = new callTask<>(1, 1000);
        FutureTask<Integer> task3 = new FutureTask<Integer>(callable3);
        Thread th3 = new Thread(task3);

        th1.start();
        th2.start();
        th3.start();

        try {
            th1.join();
            th2.join();
            th3.join();
            Integer i1 = task1.get();
            Integer i2 = task2.get();
            Integer i3 = task3.get();
            System.out.println(i1 + i2 + i3);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        new Demo().run();
    }
}
